/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ui;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import utils.StringUtils;

/**
 *
 * @author cristian
 */
public class FancyScreen extends Canvas {

    private Image image;
    private String[] text;
    private Font font = Font.getDefaultFont();

    protected void paint(Graphics g) {
        // clear up the screen
        g.setColor(255, 255, 255);
        g.fillRect(0, 0, getWidth(), getHeight());

        // draw the associated image
        if(image != null)
            g.drawImage(image, getWidth()/2, 0, Graphics.HCENTER | Graphics.TOP);

        // print the text
        g.setColor(0, 0, 0);
        if(text != null && text.length > 0)
            for(int i=0; i<text.length; i++) {
                System.out.println(text[i]);
                g.drawString(text[i], getWidth()/2, getHeight()/2+i*font.getHeight(), Graphics.HCENTER | Graphics.BASELINE);
            }

        
    }

    /**
     * @return the text
     */
    public String getText() {
        return StringUtils.join(text, " ");
    }

    /**
     * @param text the text to set
     */
    public void setText(String text) {
        this.text = StringUtils.adjustToWidth(text, font, getWidth(), ' ');
    }

    /**
     * @return the image
     */
    public Image getImage() {
        return image;
    }

    /**
     * @param image the image to set
     */
    public void setImage(Image image) {
        this.image = image;
    }

}
